﻿#pragma execution_character_set("utf-8")
#include<oaidl.h>
#include<string>
#include<iostream>
#include"SketchLayoutAlgo.h"
#include<Windows.h>
#include<algorithm>
#include<numeric>
#include<chrono>
using namespace std;



//int main() {
//
//
//	//create new class object
//	sketchLayout layout;
//
//
//	//initialize parameters[catiaApp,catiaDocs...]
//	cout << "----------------------------------------------------------------------------" << endl;
//	cout << "@CONNECTION->STATUS:" << endl;
//	cout << "----------------------------------------------------------------------------" << endl;
//	layout.connectCatia();
//	cout << endl;
//	
//	//judge if doc exists in catiaApp
//	if (FAILED(layout.getDocStatus())) {
//		return -1;
//	}
//
//
//	//output the number of sketches
//	cout << "----------------------------------------------------------------------------" << endl;
//	cout << "@SKETCHES->COUNT:" << endl;
//	cout << "----------------------------------------------------------------------------" << endl;
//	cout<<"sketches count: "<<layout.getSketchesCount()<<endl;
//	cout << endl;
//
//	//output names of all sketches
//	cout << "----------------------------------------------------------------------------" << endl;
//	cout << "SKETCH->NAME:" << endl;
//	cout << "----------------------------------------------------------------------------" << endl;
//	//SetConsoleOutputCP(65001);//Prevent the output of garbled Chinese characters
//	
//	vector<string> sketchNames=layout.getSketchesName();
//	for (auto str : sketchNames) {
//		cout << str << endl;
//	}
//	cout << endl;
//
//	
//	//output sketch's layer and sequence accroding its name
//	cout << "----------------------------------------------------------------------------" << endl;
//	cout << "LAYER INFORNATION:" << endl;
//	cout << "----------------------------------------------------------------------------" << endl;
//	cout << "sketchName\t\tlayer\t\tsequence" << endl;
//	//first:get sketchLayer, second:output variable
//	int sketchCount = layout.getSketchesCount();
//	for (int i = 1;i <= sketchCount;i++) {
//		MECMOD::SketchPtr catiaSketch = layout.getSketchByIndex(i);
//		sketchLayer catiaSketchLayer = layout.getSketchLayer(catiaSketch);
//		string name = layout.bstrtToString(catiaSketch->GetName());
//		cout << name << "\t\t" << catiaSketchLayer.layer << "\t\t" << catiaSketchLayer.sequence << endl;
//	}
//	
//
//	//paint range box according to sketchBoundingBox
//	//layout.paintSketchBoundingBox();
//
//
//	//output sketch range box information
//	layout.getSketchesBoundingBoxInformation();
//	
//
//	//[relative] sketch translation
//	//layout.sketchTranslation(catiaSketch, 0.0, -60.0);
//	
//	
//	
//	
//
//	//classification and sort, first: find sketches in the same layer, second: sort and output
//	/*cout <<"Max sketch layer: " << layout.getMaxSketchLayer() << endl;
//	int layer = 1;
//	vector<MECMOD::SketchPtr> catiaSketches=layout.findSketchesOnLayerN(layer);
//	cout <<"catia Sketches"<<"on layer"<<layer<<":  " << catiaSketches.size() << endl;
//
//	vector<MECMOD::SketchPtr> catiaSortedSketches=layout.sortSketchesOnLayerN(catiaSketches);
//
//	for (auto sketch : catiaSortedSketches) {
//		string name = layout.bstrtToString(sketch->GetName());
//		cout << "sketch's name: " << name << endl;
//	}*/
//
//
//
//	//get sketches' max bounding box
//	SketchBoundingBox catiaSketchMaxBoundingBox = layout.getMaxBoundingBox();
//	cout << "----------------------------------------------------------------------------" << endl;
//	cout << "Max bounding box Information:" << endl;
//	cout << "----------------------------------------------------------------------------" << endl;
//	cout << "width\t\t" << catiaSketchMaxBoundingBox.width << endl;
//	cout << "height\t\t" << catiaSketchMaxBoundingBox.height << endl;
//	//sketch translation rules
//	/*
//	* (1,1) (x_offset,y_offset)
//	* (1,2) (xoffset+width+gapx,y_offset)
//	* (1,3) (x_offset+(width+gapx)*2,y_offset)
//	* (layer,sequence) (x_offset+(width+gapx)*(sequence-1),y_offset-(height+gapy)*(layer-1)
//	*/
//	layout.sketchesLayoutOnLayerN(500.0, 500.0, 300.0, 300.0);
//
//
//	//calculate sketch center coordinate
//	//sketchCount = layout.getSketchesCount();
//	//for (int i = 1;i <= sketchCount;i++) {
//	//	MECMOD::SketchPtr catiaSketch;
//	//	//SketchBoundingBox catiaSketchBoundingBox=layout.getSketchBoundingBoxCOMVersion(catiaSketch);
//	//	cout << layout.bstrtToString(catiaSketch->GetName()) << endl;
//	//	//cout << "center_coordinate_x: " << catiaSketchBoundingBox.centerPoint.x_coordinate << endl;
//	//	//cout << "center_coordiante_y: " << catiaSketchBoundingBox.centerPoint.y_coordinate << endl;
//	//	cout << endl;
//	//}
//	cout << "----------------------------------------------------------------------------" << endl;
//	cout << "sketch center" << endl;
//	cout << "----------------------------------------------------------------------------" << endl;
//	int sketchNumber = layout.getSketchesCount();
//	//for (int i = 1;i <= sketchNumber;i++) {
//	//	MECMOD::SketchPtr catiaSketch = layout.getSketchByIndex(i);
//	//	//layout.paintSketchCenterPoint(catiaSketch);
//	//}
//	
//
//	return 0;
//}



int main() {
	auto start = std::chrono::high_resolution_clock::now();
	layoutFunction(30.0, 30.0, 30.0, 30.0);
	
	auto end = std::chrono::high_resolution_clock::now();
	auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
	std::cout << "time:" << duration.count()*1.0/1000 << "s" << std::endl;
	return 0;
}
